package com.ihr360.insurance.controller.benefit;

import com.ihr360.commons.lang.DateUtils;
import com.ihr360.commons.model.type.BenefitCategory;
import com.ihr360.insurance.model.dto.benefits.MandatoryBenefitsType;
import com.ihr360.insurance.model.vo.BenefitTypeVo;
import com.ihr360.insurance.service.MandatoryBenefitsTypeService;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.rest.service.SimpleRestService;
import com.ihr360.rest.webmvc.AbstractRestSimpleWithLongIdController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/mandatoryBenefitsTypes")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.BENEFIT_CODE_ADMIN,
        mainModuleName = ModuleCodeStore.Module.BENEFIT_NAME_ADMIN,
        subModuleCode = ModuleCodeStore.Module.BenefitAdmin.SI_TYPE_ADMIN_CODE,
        subModuleName = ModuleCodeStore.Module.BenefitAdmin.SI_TYPE_ADMIN_NAME,
        hasExtendsAbstractRestController = true)
public class MandatoryBenefitsTypeController extends AbstractRestSimpleWithLongIdController<MandatoryBenefitsType> {
    @Autowired
    MandatoryBenefitsTypeService benefitTypeService;

    @Override
    public SimpleRestService getSimpleRestService() {
        return benefitTypeService;
    }

    @FunctionDefinition(functionName = "获取当前可用的社保/公积金类型", functionCode = ModuleCodeStore.Function.UPDATE)
    @RequestMapping(value = "/getCurrentEnable", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public List<BenefitTypeVo> getCurrentEnabledTypes(BenefitCategory category) {
        Date yearMonthDate = DateUtils.getYearMonthDate(new Date());
        return benefitTypeService.getCurrentEnabledTypes(yearMonthDate, category);
    }
}